package com.gmrz.uaf.crypto.internal.algos;

import com.gmrz.uaf.crypto.CryptoConstants;
import com.gmrz.uaf.crypto.CryptoEngine;
import com.gmrz.uaf.crypto.sm.SM2Utils;
import com.gmrz.uaf.crypto.sm.SM3Utils;
import com.gmrz.uaf.crypto.spi.UAFAuthAlgorithmSuite;
import com.google.inject.Inject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.security.*;

public class UAFAuthAlgSM2 implements UAFAuthAlgorithmSuite {
	private static final Logger logger = LogManager.getLogger(UAFAuthAlgSM2.class);
	protected CryptoConstants.UAFAlgSign authAlgorithmSuite = null;
	protected CryptoEngine cryptoEngine = null;

	public int getSuite() {
		return this.authAlgorithmSuite.getSuite();
	}

	public String getName() {
		return this.authAlgorithmSuite.getName();
	}

	public String getHashingAlgo() {
		return this.authAlgorithmSuite.getHashingAlgo();
	}

	public UAFAuthAlgSM2(CryptoConstants.UAFAlgSign authAlgorithmSuite) {
		this.authAlgorithmSuite = authAlgorithmSuite;
	}

	@Inject
	public void setCryptoEngine(CryptoEngine cryptoEngine) {
		this.cryptoEngine = cryptoEngine;
	}

	public boolean verifySignature(PublicKey publicKey, byte[] signedData, byte[] signature)
			throws GeneralSecurityException {
		return false;
	}
	public boolean verifySignature(byte[] publicKey, byte[] signedData, byte[] signature)
			throws GeneralSecurityException {
		boolean signFlag = SM2Utils.verifySignRaw(publicKey, signedData, signature);
		return signFlag;
	}
	public byte[] hash(byte[] data) throws GeneralSecurityException {
		return SM3Utils.doSM3Hash(data);
	}

	public boolean init() {
		return true;
	}
}
